//
//  ViewController.m
//  ZFActivityView
//
//  Created by linzaifei on 2021/9/1.
//

#import "ViewController.h"
#import "ZFActivityView+alert.h"
#import "RedCoinView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self  createView];
}

-(void)createView{
    NSArray *arr = @[@"普通弹框",@"样式一弹框",@"bottom弹框",@"left弹框",@"right弹框",@"top弹框"];
    NSMutableArray *btns = [NSMutableArray array];

    NSString *str = @"V:|-100-";
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    for (int i = 0; i< arr.count; i++) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:arr[i] forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor orangeColor];
        btn.titleLabel.textColor = [UIColor whiteColor];
        btn.tag = 100+i;
        [self.view addSubview:btn];
        [btns addObject:btn];
        [btn addTarget:self action:@selector(onClickItem:) forControlEvents:UIControlEventTouchUpInside];

        btn.translatesAutoresizingMaskIntoConstraints = NO;
 
        if (i==arr.count-1) {
            str = [str stringByAppendingFormat:@"[btn%d(==50)]",i];
        }else{
            str = [str stringByAppendingFormat:@"[btn%d(==50)]-30-",i];
        }
        [dic setValue:btn forKey:[NSString stringWithFormat:@"btn%d",i]];
        
        NSString *horStr = [NSString stringWithFormat:@"H:|-50-[btn%d]-50-|",i];
        NSArray *arr = [NSLayoutConstraint constraintsWithVisualFormat:horStr options:0 metrics:0 views:@{[NSString stringWithFormat:@"btn%d",i]:btn}];
        [self.view addConstraints:arr];
    }
        

    
    NSArray<NSLayoutConstraint *> *layouts = [NSLayoutConstraint constraintsWithVisualFormat:str options:0 metrics:0 views:dic];
    [self.view addConstraints:layouts];
    
}
-(void)onClickItem:(UIButton *)button{
    NSString *key =[NSString stringWithFormat:@"alert%ld",button.tag-100];
    [self performSelector:NSSelectorFromString(key)];
}
-(void)alert0{
    [[ZFActivityView activityView:^(ZFActivityBackgroundView * _Nonnull contentView) {
     
            RedCoinView *coinView = [[RedCoinView alloc] init];
            [contentView addSubview:coinView];
        coinView.translatesAutoresizingMaskIntoConstraints = NO;
        
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[fontImageView]-0-|" options:0 metrics:0 views:@{@"fontImageView":coinView}]];
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[fontImageView]-0-|" options:0 metrics:0 views:@{@"fontImageView":coinView}]];
    }config:^(ZFActivityView * _Nullable activityView) {
            activityView.backgroundView.color = [UIColor colorWithWhite:0 alpha:0.4];
            activityView.backgroundView.style = ZFActivityBackgroundStyleSolidColor;
            activityView.animationType = ActivityAnimationZoom;
            activityView.canTouchBackground = YES;
        activityView.needRemoveSuperView = YES;
        
    } inView:self.view]showAnimated:YES] ;
    
}
-(void)alert1{
    [[ZFActivityView activityView:^(ZFActivityBackgroundView * _Nonnull contentView) {
        
        contentView.backgroundColor = [UIColor orangeColor];
    }config:^(ZFActivityView * _Nullable activityView) {
            activityView.animationType = ActivityAnimationZoom;
            activityView.canTouchBackground = YES;
    } inView:self.view]showAnimated:YES] ;
}
-(void)alert2{
    [[ZFActivityView activityView:^(ZFActivityBackgroundView * _Nonnull contentView) {
        
        contentView.backgroundColor = [UIColor orangeColor];
        
        UIView *view = [[UIView alloc] init];
        [contentView addSubview:view];
        view.backgroundColor = [UIColor greenColor];
        view.translatesAutoresizingMaskIntoConstraints = NO;
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[fontImageView]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[fontImageView(==300)]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
    }config:^(ZFActivityView * _Nullable activityView) {
            activityView.animationType = ActivityAnimationPopBottom;
            activityView.canTouchBackground = YES;
    } inView:self.view]showAnimated:YES] ;
}
-(void)alert3{
    [[ZFActivityView activityView:^(ZFActivityBackgroundView * _Nonnull contentView) {
        
        contentView.backgroundColor = [UIColor orangeColor];
        UIView *view = [[UIView alloc] init];
        [contentView addSubview:view];
        view.backgroundColor = [UIColor greenColor];
        view.translatesAutoresizingMaskIntoConstraints = NO;
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[fontImageView(==200)]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[fontImageView]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
    }config:^(ZFActivityView * _Nullable activityView) {
            activityView.animationType = ActivityAnimationPopLeft;
            activityView.canTouchBackground = YES;
        activityView.duration = 0.5f;
    } inView:self.view]showAnimated:YES] ;
}
-(void)alert4{
    [[ZFActivityView activityView:^(ZFActivityBackgroundView * _Nonnull contentView) {
        
        contentView.backgroundColor = [UIColor orangeColor];
        UIView *view = [[UIView alloc] init];
        [contentView addSubview:view];
        view.backgroundColor = [UIColor greenColor];
        view.translatesAutoresizingMaskIntoConstraints = NO;
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[fontImageView(==200)]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[fontImageView]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
    }config:^(ZFActivityView * _Nullable activityView) {
            activityView.animationType = ActivityAnimationPopRight;
            activityView.canTouchBackground = YES;
        activityView.duration = 0.5;
    } inView:self.view]showAnimated:YES] ;
}
-(void)alert5{
    [[ZFActivityView activityView:^(ZFActivityBackgroundView * _Nonnull contentView) {
        
        contentView.backgroundColor = [UIColor orangeColor];
        UIView *view = [[UIView alloc] init];
        [contentView addSubview:view];
        view.backgroundColor = [UIColor greenColor];
        view.translatesAutoresizingMaskIntoConstraints = NO;
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[fontImageView]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
        [contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[fontImageView(==300)]-0-|" options:0 metrics:0 views:@{@"fontImageView":view}]];
    }config:^(ZFActivityView * _Nullable activityView) {
            activityView.animationType = ActivityAnimationPopTop;
            activityView.canTouchBackground = YES;
        activityView.duration = 0.5;
    } inView:self.view]showAnimated:YES] ;
}
@end
